package utils

import (
	"math"
)

type PageTable struct {
	Fields    string
	Table     string
	Where     string
	PageIndex int
	PageSize  int
	Order     string
	GroupBy   string
}

type PageParam struct {
	PageIndex int `json:"pageNo"`
	PageSize  int `json:"pageSize"`
}

type PageData struct {
	PageIndex  int         `json:"pageNo"`
	PageSize   int         `json:"pageSize"`
	PageNumber int         `json:"pageNum"`
	Count      int64       `json:"totalCount"`
	Data       interface{} `json:"data"`
}

const PageSize = 10

func GetPageIndex(pageIndex int) int {
	if pageIndex <= 0 {
		pageIndex = 1
	}
	return pageIndex
}

func GetPageSize(pageSize int) int {
	if pageSize <= 0 {
		pageSize = PageSize
	}
	if pageSize > 100 {
		//防止大量数据查询
		pageSize = 100
	}
	return pageSize
}

type Count struct {
	Count int64
}

func GetPageNumber(count int64, pageSize int) int {
	return int(math.Ceil(float64(count) / float64(pageSize)))
}
